Merge "Put the HTML attribute whitelist closer to HTML5"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 2 Nov 2013 14:07:07 +0000 (14:07 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 2 Nov 2013 14:07:07 +0000 (14:07 +0000)
1  2 
tests/phpunit/includes/SanitizerTest.php

@@@ -1,9 -1,5 +1,9 @@@
  <?php
  
 +/**
 + * @todo Tests covering decodeCharReferences can be refactored into a single
 + * method and dataprovider.
 + */
  class SanitizerTest extends MediaWikiTestCase {
  
        protected function setUp() {
                AutoLoader::loadClass( 'Sanitizer' );
        }
  
 -      function testDecodeNamedEntities() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testDecodeNamedEntities() {
                $this->assertEquals(
                        "\xc3\xa9cole",
                        Sanitizer::decodeCharReferences( '&eacute;cole' ),
                );
        }
  
 -      function testDecodeNumericEntities() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testDecodeNumericEntities() {
                $this->assertEquals(
                        "\xc4\x88io bonas dans l'\xc3\xa9cole!",
                        Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ),
                );
        }
  
 -      function testDecodeMixedEntities() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testDecodeMixedEntities() {
                $this->assertEquals(
                        "\xc4\x88io bonas dans l'\xc3\xa9cole!",
                        Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ),
                );
        }
  
 -      function testDecodeMixedComplexEntities() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testDecodeMixedComplexEntities() {
                $this->assertEquals(
                        "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
                        Sanitizer::decodeCharReferences(
                );
        }
  
 -      function testInvalidAmpersand() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testInvalidAmpersand() {
                $this->assertEquals(
                        'a & b',
                        Sanitizer::decodeCharReferences( 'a & b' ),
                );
        }
  
 -      function testInvalidEntities() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testInvalidEntities() {
                $this->assertEquals(
                        '&foo;',
                        Sanitizer::decodeCharReferences( '&foo;' ),
                );
        }
  
 -      function testInvalidNumberedEntities() {
 +      /**
 +       * @covers Sanitizer::decodeCharReferences
 +       */
 +      public function testInvalidNumberedEntities() {
                $this->assertEquals( UTF8_REPLACEMENT, Sanitizer::decodeCharReferences( "&#88888888888888;" ), 'Invalid numbered entity' );
        }
  
@@@ -94,7 -69,7 +94,7 @@@
         * @param String $tag Name of an HTML5 element (ie: 'video')
         * @param Boolean $escaped Wheter sanitizer let the tag in or escape it (ie: '&lt;video&gt;')
         */
 -      function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) {
 +      public function testRemovehtmltagsOnHtml5Tags( $tag, $escaped ) {
                $this->setMwGlobals( array(
                        'wgUseTidy' => false
                ) );
  
        /**
         * @dataProvider dataRemoveHTMLtags
 +       * @covers Sanitizer::removeHTMLtags
         */
 -      function testRemoveHTMLtags( $input, $output, $msg = null ) {
 +      public function testRemoveHTMLtags( $input, $output, $msg = null ) {
                $GLOBALS['wgUseTidy'] = false;
                $this->assertEquals( $output, Sanitizer::removeHTMLtags( $input ), $msg );
        }
         * @dataProvider provideTagAttributesToDecode
         * @covers Sanitizer::decodeTagAttributes
         */
 -      function testDecodeTagAttributes( $expected, $attributes, $message = '' ) {
 +      public function testDecodeTagAttributes( $expected, $attributes, $message = '' ) {
                $this->assertEquals( $expected,
                        Sanitizer::decodeTagAttributes( $attributes ),
                        $message
         * @dataProvider provideDeprecatedAttributes
         * @covers Sanitizer::fixTagAttributes
         */
 -      function testDeprecatedAttributesUnaltered( $inputAttr, $inputEl, $message = '' ) {
 +      public function testDeprecatedAttributesUnaltered( $inputAttr, $inputEl, $message = '' ) {
                $this->assertEquals( " $inputAttr",
                        Sanitizer::fixTagAttributes( $inputAttr, $inputEl ),
                        $message
                        array( 'align="left"', 'tr' ),
                        array( 'align="center"', 'div' ),
                        array( 'align="left"', 'h1' ),
-                       array( 'align="left"', 'span' ),
+                       array( 'align="left"', 'p' ),
                );
        }
  
         * @dataProvider provideCssCommentsFixtures
         * @covers Sanitizer::checkCss
         */
 -      function testCssCommentsChecking( $expected, $css, $message = '' ) {
 +      public function testCssCommentsChecking( $expected, $css, $message = '' ) {
                $this->assertEquals( $expected,
                        Sanitizer::checkCss( $css ),
                        $message
  
        /**
         * @dataProvider provideAttributeSupport
 +       * @covers Sanitizer::fixTagAttributes
         */
 -      function testAttributeSupport( $tag, $attributes, $expected, $message ) {
 +      public function testAttributeSupport( $tag, $attributes, $expected, $message ) {
                $this->assertEquals( $expected,
                        Sanitizer::fixTagAttributes( $attributes, $tag ),
                        $message